﻿/****************************************************************************************
 * Copyright © 2020 - 2023 by AngryKeyboard.
 * SFML_俄罗斯方块 is licensed under MulanOWL BY v1.
 * You can use this software according to the terms and conditions of the MulanOWL BY v1.
 * You may obtain a copy of MulanOWL BY v1 at:
 *          http://license.coscl.org.cn/MulanOWLBYv1
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
 * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
 * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
 * See the MulanOWL BY v1 for more details.
****************************************************************************************/
#pragma once
#include "const.h"
#include "struct.h"

//方块类
class CBlock {
  friend class CAutoFill;

public:
  CBlock();
  CBlock(int Shape);
  CBlock(const CBlock &block);

  /*************
  与运动有关的接口
  *************/
  bool drop1Step(const int table[ROW_COUNT][COL_COUNT]);  //下落一格，返回值为是否需要固化
  void dropToBottom(const int table[ROW_COUNT][COL_COUNT]); //下落到底部
  void moveLeftRight(const int table[ROW_COUNT][COL_COUNT], int offset = 0);//左右平移，offset<0往左移动，offset>0往右移
  void rotate(const int table[ROW_COUNT][COL_COUNT], int rotateDirection = CLOCKWISE);//旋转（默认顺时针）


  /******
  数据读取
  ******/
  int Shape()const;
  int Direction()const;
  const SPoint *Pos()const;

protected:
  /*****************
  与状态检查有关的接口
  *****************/
  bool ifOverBottom(const int table[ROW_COUNT][COL_COUNT]); //检查方块是否越过底部
  void normalize(); //左右越界时，把方块平移到游戏区域内

  /*************
  与运动有关的接口
  *************/
  void move(int direction = DOWN, int step = 1);  //无视体积碰撞，朝指定方向移动指定格数（默认向下一步）
  void rotateClockwise();   //顺时针旋转
  void rotateAnticlockwise(); //逆时针旋转

private:
  int m_nShape;     //形状
  int m_nDirection;   //方向
  SPoint m_Pos[BLOCK_POINT_COUNT];    //坐标（4个点）
};
